package mosync.mobilelualiveditor;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComponent;
import javax.swing.JTextField;

public class TextfieldController extends PropertyController
{

	public TextfieldController(String name)
	{
		super(name);
	}

	public String getCallbackTemplateHeader(String name)
	{
		return "function " + name + "_textChanged(text)";
	}

	public JComponent createComponent()
	{
		final JTextField field = new JTextField();

		// UNUSED: slider.setMaximumSize(new Dimension(5000, 32));
		field.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				String text = "" + field.getText();
				String code = mName + "_textChanged(\"" + text + "\")\n";
				Evaluator.getSingleton().evaluate(code);
			}
		});

		return field;
	}
}
